/**
 * Created by WT-SUN on 2017/4/20.
 */

$(function () {
    queryDepartmentTree();
    $('#btn_save').on('click', function () {
        submitForm();
    });
    attachFileRowEvent('occZdTb', ROOT_PATH + '/occupationalHealth/phyData/upload.shtml');
    if (arrForbid.length>0){
        occforbidTb();
    }else {
        $("#occforbidTbDiv").hide();
    }
    if(arrDoubt.length>0){
        occdoubtTb();
    }else {
        $("#occdoubtTbDiv").hide();
    }
    if(arrOther.length>0){
        occotherTb();
    }else {
        $("#occotherTbDiv").hide();
    }
    $("#danwei").textbox('setValue', danweiName).textbox('setText', danweiName);
    $("#zyweihai").textbox('setValue', phyHarmIdsName).textbox('setText', phyHarmIdsName);
    /**
     * 职业病诊断
     */
    if (arrphyDiagnosis.length>0){
        $("#occZdTbDiv").show();
        occZdTb();
    }else {
        $("#occZdTbDiv").hide();
    }
    var companyId=$("#nowCompanyName").val();
    $('#nowPosition').combobox({
        url:ROOT_PATH + '/permission/post/findByDeptId.shtml?deptId='+companyId,
        valueField: 'id',
        textField: 'text',
        prompt:'请选择'
    });
    /**
     * 调岗
     */
    if($("#conclusionTgy").is(":checked")) {
        $("#tiaogangDiv").show();
    }else {
        $("#tiaogangDiv").hide();
    }
    /**
     * 职业病诊断
     */
    if($("#conclusionZdy").is(":checked")) {
        $("#occZdTbDiv").show();
        occZdTb();
    }else {
        $("#occZdTbDiv").hide();
    }

    occReviewTb();
    initTb();
    checkBoxFun();

     
    /*positionCom('#nowPosition');
    positionCom('#orgPosition');*/
    /*$('div.datagrid-body').click(function(){
        if(editIndex_occZdTb != undefined)
            $('#occZdTb').datagrid('endEdit', editIndex_occZdTb);
    });*/
});
function checkBoxFun() {
    $("#conclusionZdy").click(function () {
        if($(this).is(":checked")) {
            $("#occZdTbDiv").show();
            occZdTb();
        }else {
            $("#occZdTbDiv").hide();
        }
    });
    $("#conclusionTgy").click(function () {
        if($(this).is(":checked")) {
            $("#tiaogangDiv").show();
        }else {
            $("#tiaogangDiv").hide();
        }
    });
}

var editIndex_occReviewTb = undefined;//复查信息
var editIndex_occZdTb = undefined;//职业病诊断
function endEditingRtb(){
    if (editIndex_occReviewTb == undefined){return true}
    if ($('#occReviewTb').datagrid('validateRow', editIndex_occReviewTb)){
        $('#occReviewTb').datagrid('endEdit', editIndex_occReviewTb);
        editIndex_occReviewTb = undefined;
        return true;
    } else {
        return false;
    }
}


function endEditingZtb(){
    if (editIndex_occZdTb == undefined){return true}
    if ($('#occZdTb').datagrid('validateRow', editIndex_occZdTb)){
        $('#occZdTb').datagrid('endEdit', editIndex_occZdTb);
        editIndex_occZdTb = undefined;
        return true;
    } else {
        return false;
    }
}
function initTb() {
    $('#occReviewTb_save').on('click', function () {
        if (endEditingRtb()){
           // $('#occReviewTb').datagrid('acceptChanges');
        }
    });
    $('#occReviewTb_add').on('click', function () {
        var phyId=$("#phyId").val();
        if(endEditingZtb()){

        }
        if (endEditingRtb()){
            $('#occReviewTb').datagrid('appendRow',{
                phyId: phyId
            });
            editIndex_occReviewTb = $('#occReviewTb').datagrid('getRows').length-1;
            $('#occReviewTb').datagrid('selectRow', editIndex_occReviewTb).datagrid('beginEdit', editIndex_occReviewTb);
        }
    });
    $('#occReviewTb_remove').on('click', function () {
        if (editIndex_occReviewTb == undefined){return}
        $('#occReviewTb').datagrid('cancelEdit', editIndex_occReviewTb).datagrid('deleteRow', editIndex_occReviewTb);
        editIndex_occReviewTb = undefined;
    });
//-------------------------------
    $('#occZdTb_save').on('click', function () {
        if (endEditingZtb()){
            // $('#occReviewTb').datagrid('acceptChanges');
        }
    });
    $('#occZdTb_add').on('click', function () {
        var phyId=$("#phyId").val();
        if(endEditingRtb()){

        }
        if (endEditingZtb()){
            var id = $.generateUUID();
            $('#occZdTb').datagrid('appendRow',{
                id:id,
                oldid:id,
                phyId: phyId
            });
            editIndex_occZdTb = $('#occZdTb').datagrid('getRows').length-1;
            $('#occZdTb').datagrid('selectRow', editIndex_occZdTb).datagrid('beginEdit', editIndex_occZdTb);
        }
    });
    $('#occZdTb_remove').on('click', function () {
        if (editIndex_occZdTb == undefined){return}
        $('#occZdTb').datagrid('cancelEdit', editIndex_occZdTb).datagrid('deleteRow', editIndex_occZdTb);
        editIndex_occZdTb = undefined;
    });
}
function occReviewTb() {
    $('#occReviewTb').datagrid({
        fitColumns: true,
        idField: 'id',
        rownumbers: true,
        data:arrReview,
        sortOrder: true,
        singleSelect: true,
        striped: true,
        fit: false,
        height: 200,
        columns: [[
            {
                field: 'id', title: 'id', hidden:true,width: 20
            },
            {field: 'phyId', title: 'phyId', hidden:true,width: 100},
            {field: 'reConclusion', hidden:true,title: '复查Id', width: 100,editor: {type: 'textbox',options:{editable:false}}},
            {field: 'reConclusionName', hidden:true,title: '复查结论C', width: 100,editor: {type: 'textbox',options:{editable:false}}},
            {field: 'reConclusionNameC', title: '复查结论', width: 100,formatter:function(value,row){
                return row.reConclusionName;
            },
                editor: {
                    type: 'combobox',
                    options: {
                        data: arrReCom,
                        valueField: 'id',
                        editable:false,
                        textField: 'text',
                        required: true,
                        onSelect:function (r) {
                            if (editIndex_occReviewTb!=undefined){
                                var ed = $("#occReviewTb").datagrid('getEditor', { index: editIndex_occReviewTb, field: 'reConclusionName' });
                                var edId = $("#occReviewTb").datagrid('getEditor', { index: editIndex_occReviewTb, field: 'reConclusion' });
                                $(ed.target).textbox('setValue', r.text).textbox('setText', r.text);
                                $(edId.target).textbox('setValue', r.id).textbox('setText', r.id);
                            }
                         }
                    }
                }},
            {field: 'diseasesNameId', hidden:true,title: '职业病名称Id', width: 100,editor: {type: 'textbox',options:{editable:false}}},
            {field: 'diseasesName', title: '职业病名称', width: 100,
                editor: {
                    type: 'textbox',
                    options:{
                        iconWidth: 20,
                        editable:false,
                        //required:true,
                        icons: [{
                            iconCls: 'icon-add',
                            handler: function(e){
                                add_dis_funcRe();
                            }
                        },{
                            iconCls: 'icon-remove',
                            handler: function(e){
                                $(e.data.target).textbox('clear');
                                var edId = $("#occReviewTb").datagrid('getEditor', { index: editIndex_occReviewTb, field: 'diseasesNameId' });
                                $(edId.target).textbox('setValue', '').textbox('setText', '');
                            }
                        }]
                    }
                }},
            {field: 'serviceId', hidden:true,title: '单位Id', width: 100,editor: {type: 'textbox',options:{editable:false}}},
            {field: 'forbidWork', title: '禁忌作业', width: 80,  editor: { type: 'textbox',options:{} }},
            {field: 'diagnosisDate', title: '诊断日期', width: 100,editor: {type: 'datebox', options: {required: true,editable:false, validateOnBlur: true}}},
            {field: 'serviceName', title: '诊断单位', width: 100,
                editor: {
                    type: 'textbox',
                    options:{
                        iconWidth: 20,
                        editable:false,
                        required:true,
                        icons: [{
                            iconCls: 'icon-add',
                            handler: function(e){
                                openSerViceTbRe();
                            }
                        },{
                            iconCls: 'icon-remove',
                            handler: function(e){
                                $(e.data.target).textbox('clear');
                                var edId = $("#occReviewTb").datagrid('getEditor', { index: editIndex_occReviewTb, field: 'serviceId' });
                                $(edId.target).textbox('setValue','').textbox('setText', '');
                            }
                        }]
                    }
                }},
            {field: 'remarks', title: '备注', width: 100, editor: { type: 'textbox' }},
            {field: 'addTime', title: '登记日期', width: 80}
        ]],
        onClickRow:function (index, row) {
            if (editIndex_occReviewTb != index){
                if (endEditingRtb()){
                    $('#occReviewTb').datagrid('selectRow', index).datagrid('beginEdit', index);
                    editIndex_occReviewTb = index;
                    var edIdC = $("#occReviewTb").datagrid('getEditor', { index: index, field: 'reConclusionNameC' });
                    $(edIdC.target).combobox('setValue', row.reConclusion);
                }else {
                    $('#occReviewTb').datagrid('selectRow', editIndex_occReviewTb);
                }
            }
        }
    });
}
function occZdTb() {
    $('#occZdTb').datagrid({
        fitColumns: true,
        //idField: 'id',
        striped: true,
        rownumbers: true,
        data:arrphyDiagnosis,
        sortOrder: true,
        singleSelect: true,
        fit: false,
        height: 200,
        columns: [[
            {
                field: 'id', title: 'id', hidden:true,width: 20,
            },
            {
                field: 'oldid', title: 'oldid', hidden:true,width: 20,
            },
            {field: 'phyId', title: 'phyId', hidden:true,width: 100},
            {field: 'conclusionId', hidden:true,title: '诊断结论Id', width: 100,editor: {type: 'textbox',options:{editable:false}}},
            {field: 'conclusionName', hidden:true,title: '诊断结论C', width: 100,editor: {type: 'textbox',options:{editable:false}}},
            {field: 'conclusionNameOld', hidden:true,title: '职业病结论', width: 100},
            {field: 'conclusionNameC', title: '诊断结论', width: 100,formatter:function(value,row){
                return row.conclusionName;
            },
                editor: {
                    type: 'combobox',
                    options: {
                        data: arrZyCom,
                        valueField: 'id',
                        editable:false,
                        textField: 'text',
                        required: true,
                        onSelect:function (r) {
                            if (editIndex_occZdTb!=undefined){
                                var ed = $("#occZdTb").datagrid('getEditor', { index: editIndex_occZdTb, field: 'conclusionName' });
                                var edId = $("#occZdTb").datagrid('getEditor', { index: editIndex_occZdTb, field: 'conclusionId' });
                                $(ed.target).textbox('setValue', r.text).textbox('setText', r.text);
                                $(edId.target).textbox('setValue', r.id).textbox('setText', r.id);
                                var zy = $("#occZdTb").datagrid('getEditor', { index: editIndex_occZdTb, field: 'isZy' });
                                var zyb = $("#occZdTb").datagrid('getEditor', { index: editIndex_occZdTb, field: 'isZyb' });
                                if(r.text=="职业病"){
                                    $(zyb.target).textbox('setValue', '0').textbox('setText', '0');
                                    var rowd= $("#occZdTb").datagrid('getSelected');
                                    if(rowd.conclusionNameOld!="职业病"){
                                        $(zy.target).textbox('setValue', 'isZy').textbox('setText', 'isZy');
                                    }else {
                                        $(zy.target).textbox('setValue', 'noZy').textbox('setText', 'noZy');
                                    }
                                }else {
                                    $(zyb.target).textbox('setValue', '1').textbox('setText', '1');
                                    $(zy.target).textbox('setValue', 'noZy').textbox('setText', 'noZy');
                                }
                            }
                        }
                    }
                }},
            {field: 'isZyb', hidden:true,title: '是否为职业病', width: 100,editor: {type: 'textbox',options:{editable:false}}},
            {field: 'isZy', hidden:true,title: '是否添加职业病台帐', width: 100,editor: {type: 'textbox',options:{editable:false}}},
            {field: 'diseasesNameId', hidden:true,title: '职业病名称Id', width: 100,editor: {type: 'textbox',options:{editable:false}}},
            {field: 'diseasesName', title: '职业病名称', width: 100,
                editor: {
                    type: 'textbox',
                    options:{
                        iconWidth: 20,
                        editable:false,
                        //required:true,
                        icons: [{
                            iconCls: 'icon-add',
                            handler: function(e){
                                add_dis_funcZd();
                            }
                        },{
                            iconCls: 'icon-remove',
                            handler: function(e){
                                $(e.data.target).textbox('clear');
                                var edId = $("#occZdTb").datagrid('getEditor', { index: editIndex_occZdTb, field: 'diseasesNameId' });
                                $(edId.target).textbox('setValue', '').textbox('setText', '');
                            }
                        }]
                    }
                }},
            {field: 'diagnosisDate', title: '诊断日期', width: 100,editor: {type: 'datebox', options: {required: true,editable:false, validateOnBlur: true}}},
            {field: 'serviceId', hidden:true,title: '单位Id', width: 100,editor: {type: 'textbox',options:{editable:false}}},
            {field: 'forbidWork', title: '禁忌作业', width: 80,  editor: { type: 'textbox',options:{} }},
            {field: 'serviceName', title: '诊断单位', width: 100,
                editor: {
                    type: 'textbox',
                    options:{
                        iconWidth: 20,
                        editable:false,
                        required:true,
                        icons: [{
                            iconCls: 'icon-add',
                            handler: function(e){
                                openSerViceTbZd();
                            }
                        },{
                            iconCls: 'icon-remove',
                            handler: function(e){
                                $(e.data.target).textbox('clear');
                                var edId = $("#occZdTb").datagrid('getEditor', { index: editIndex_occZdTb, field: 'serviceId' });
                                $(edId.target).textbox('setValue', '').textbox('setText', '');
                            }
                        }]
                    }
                }},
            {field: 'remarks', title: '备注', width: 100, editor: { type: 'textbox' }},
            {field: 'startTime', title: '开始接触时间', width: 100,editor: {type: 'datebox', options: {editable:false}}},
            {field: 'workYears', title: '工龄', width: 100, editor: { type: 'textbox' }},
            {field: 'zgSituation', title: '转归情况', width: 80,editor: { type: 'textbox' }},
            {
                field: 'accessory', title: '附件', width: 50, align: 'center', formatter: function (value, row, index) {
                return '<a id="occZdTb_btn_file_' + row.oldid + '" href="javascript:void(0)" class="easyui-linkbutton text-primary" plain="true">附件</a> ';
            }}
        ]],
        onClickRow:function (index, row) {
            if (editIndex_occZdTb != index){
                if (endEditingZtb()){
                    $('#occZdTb').datagrid('selectRow', index).datagrid('beginEdit', index);
                    editIndex_occZdTb = index;
                    var edIdC = $("#occZdTb").datagrid('getEditor', { index: index, field: 'conclusionNameC' });
                    $(edIdC.target).combobox('setValue', row.conclusionId);
                    var zy = $("#occZdTb").datagrid('getEditor', { index: index, field: 'isZy' });
                    $(zy.target).textbox('setValue', 'noZy').textbox('setText', 'noZy');
                }else {
                    $('#occZdTb').datagrid('selectRow', editIndex_occZdTb);
                }
            }
        }
    });
}
function add_dis_funcRe() {
    WindowManager.openLayer({
        type: 2,
        title: '选择职业病',
        area: ['850px', '70%'],
        content: ROOT_PATH + '/occupationalHealth/occDiseases/disTb.shtml',
        callBack:function(data){
            getSelectedDisRe(data);
        }
    });
}
function getSelectedDisRe(data) {
    if (editIndex_occReviewTb!=undefined){
        var ed = $("#occReviewTb").datagrid('getEditor', { index: editIndex_occReviewTb, field: 'diseasesName' });
        var edId = $("#occReviewTb").datagrid('getEditor', { index: editIndex_occReviewTb, field: 'diseasesNameId' });
        $(ed.target).textbox('setValue', data[0].diseasesName).textbox('setText', data[0].diseasesName);
        $(edId.target).textbox('setValue', data[0].id).textbox('setText', data[0].id);
    }
}
function add_dis_funcZd() {
    WindowManager.openLayer({
        type: 2,
        title: '选择职业病',
        area: ['850px', '70%'],
        content: ROOT_PATH + '/occupationalHealth/occDiseases/disTb.shtml',
        callBack:function(data){
            getSelectedDisZd(data);
        }
    });
}
function getSelectedDisZd(data) {
    if (editIndex_occZdTb!=undefined){
        var ed = $("#occZdTb").datagrid('getEditor', { index: editIndex_occZdTb, field: 'diseasesName' });
        var edId = $("#occZdTb").datagrid('getEditor', { index: editIndex_occZdTb, field: 'diseasesNameId' });
        $(ed.target).textbox('setValue', data[0].diseasesName).textbox('setText', data[0].diseasesName);
        $(edId.target).textbox('setValue', data[0].id).textbox('setText', data[0].id);
    }
}
function openSerViceTbRe() {
    WindowManager.openLayer({
        type: 2,
        title: '选择服务机构',
        area: ['850px', '70%'],
        content: ROOT_PATH + '/occupationalHealth/hseServiceOrg/orgTb.shtml',
        callBack:function(data){
            getSelectedOrgRe(data);
        }
    });
}
function getSelectedOrgRe(data) {
    if (editIndex_occReviewTb!=undefined){
        var ed = $("#occReviewTb").datagrid('getEditor', { index: editIndex_occReviewTb, field: 'serviceName' });
        var edId = $("#occReviewTb").datagrid('getEditor', { index: editIndex_occReviewTb, field: 'serviceId' });
        $(ed.target).textbox('setValue', data[0].serviceName).textbox('setText', data[0].serviceName);
        $(edId.target).textbox('setValue', data[0].id).textbox('setText', data[0].id);
    }
}
function openSerViceTbZd() {
    WindowManager.openLayer({
        type: 2,
        title: '选择服务机构',
        area: ['850px', '70%'],
        content: ROOT_PATH + '/occupationalHealth/hseServiceOrg/orgTb.shtml',
        callBack:function(data){
            getSelectedOrgZd(data);
        }
    });
}
function getSelectedOrgZd(data) {
    if (editIndex_occZdTb!=undefined){
        var ed = $("#occZdTb").datagrid('getEditor', { index: editIndex_occZdTb, field: 'serviceName' });
        var edId = $("#occZdTb").datagrid('getEditor', { index: editIndex_occZdTb, field: 'serviceId' });
        $(ed.target).textbox('setValue', data[0].serviceName).textbox('setText', data[0].serviceName);
        $(edId.target).textbox('setValue', data[0].id).textbox('setText', data[0].id);
    }
}

/**
 * 职业禁忌
 */
function occforbidTb() {
    $('#occforbidTb').datagrid({
        fitColumns: true,
        //pagination: true,
        idField: 'id',
        data:arrForbid,
        rownumbers: true,
        sortOrder: true,
        singleSelect: true,
        striped: true,
        fit: false,
        height: 200,
        columns: [[
            {
                field: 'id',
                checkbox: true
            },
            {field: 'forbidName', title: '职业禁忌证名称', width: 100},
            {field: 'forbidWork', title: '禁忌作业', width: 100},
            {field: 'remarks', title: '备注', width: 100}
        ]],
    });
}
/**
 * 疑似职业病
 */
function occdoubtTb() {
    $('#occdoubtTb').datagrid({
        fitColumns: true,
        data:arrDoubt,
        //pagination: true,
        idField: 'id',
        rownumbers: true,
        sortOrder: true,
        singleSelect: true,
        striped: true,
        fit: false,
        height: 200,
        columns: [[
            {
                field: 'id',
                checkbox: true
            },
            {field: 'diseasesName', title: '职业病名称', width: 100},
            {field: 'diseasesCode', title: '编码', width: 100},
            {field: 'remarks', title: '备注', width: 100}
        ]]
    });
}
/**
 * 其它疾病或异常
 */
function occotherTb() {
    $('#occotherTb').datagrid({
        fitColumns: true,
        idField: 'id',
        data:arrOther,
        rownumbers: true,
        sortOrder: true,
        singleSelect: true,
        striped: true,
        fit: false,
        height: 200,
        columns: [[
            {
                field: 'id',
                checkbox: true
            },
            {field: 'diseasesName', title: '疾病名称', width: 100},
            {field: 'remarks', title: '备注', width: 100}
        ]]
    });
}


/**
 * 查询部门树方法
 */
function queryDepartmentTree(){
    $.ajax({
        url:ROOT_PATH + '/permission/department/getDepartmentTree.shtml',//提交地址
        data:{parentId : 0},//将表单数据序列化
        type:"POST",
        dataType:"json",
        success:function(result){
            $('#nowCompanyName').combotree(
                {
                    data:result,
                    require:true,
                    prompt:'请选择',
                    loadFilter:function(data){
                        var newData = new Array();
                        newData.push({id:"",text:'请选择'});
                        newData.push(data[0]);
                        return newData;
                    },
                    onSelect:function (record){
                        $('#nowPosition').combobox('setValue','');
                        $('#nowPosition').combobox('reload',ROOT_PATH + '/permission/post/findByDeptId.shtml?deptId='+record.id);
                    }
                }
            );
        }
    });
}
function positionCom(id) {
    $(id).combobox({
        url: ROOT_PATH + '/permission/dictionary/queryDictionaryByDictionaryTypeCode.shtml?code=' + CONSTANT.DictionaryTypeDefConstants.USER_POST,
        valueField: 'id',
        textField: 'text',
        loadFilter: function (data) {
            data.unshift({
                id: '',
                text: '请选择'
            });
            return data;
        }
    });
}
/**
 * 保存数据
 * @returns {jQuery}
 */
function submitForm() {
    if (!$('#yichangchuzhi').form('validate')) { layer.alert("请正确填写信息"); return $('#yichangchuzhi').form('validate');}
    var ckL=$("input[name='yConclusion']:checked");
    if (ckL.length==0){
        layer.alert("请选处理状态！");
        return;
    }
    var objParams = $('#yichangchuzhi').serializeJson();
    if(typeof (objParams.yConclusion)=='undefined'){
        layer.alert("请选择体检处理状态！");
        return;
    }
    //复查信息
    if (endEditingRtb()){
        $('#occReviewTb').datagrid('acceptChanges');
    }
    var objArrF=$('#occReviewTb').datagrid('getData');
    if(objArrF.total>0){
        var occReviewTb= JSON.stringify(objArrF.rows);
        objParams.occReviewTb=occReviewTb;
    }
    //职业病诊断
    if($("#conclusionZdy").is(":checked")){
        if (endEditingZtb()){
            $('#occZdTb').datagrid('acceptChanges');
        }
        var objArr1=$('#occZdTb').datagrid('getData');
        if(objArr1.total>0){
            var occZdTb= JSON.stringify(objArr1.rows);
            objParams.occZdTb=occZdTb;
        }else {
            layer.alert("请添加职业病诊断数据或者取消勾选！");
            return;
        }
    }
    $.ajax({
        url:ROOT_PATH + '/occupationalHealth/phyData/insertYcSelective.shtml',//提交地址
        data:objParams,
        type:"POST",
        dataType:"json",
        //contentType:"application/json",
        success: function (result) {
            if (result.success) {
                layer.msg('保存成功', {
                    icon: 1,
                    time: 1000
                }, function () {
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                    $.getIframeWindow().reLoadData();
                });
            }
            else {
                layer.msg('保存失败', {
                    icon: 2,
                    time: 1000
                });
            }
        }
    });
}
var attachFileRowEvent = function (dataGridId, url) {
    $('body').on('click', '[id^=' + dataGridId + '_btn_file_]', function () {
        /*if (endEditingZtb()){
            //$('#occZdTb').datagrid('acceptChanges');
        }*/
        var id = this.id.replace(dataGridId + '_btn_file_', '');
        var uploadUserId = $(':input[name=uploadUserId]').val();
        var packageKey = 'occZdTbFile';
        var layerIndex = parent.layer.open({
            type: 2,
            title: '上传附件',
            area: ['500px', '300px'],
            content: ROOT_PATH + '/accessory/fileUpload.shtml?resourceId=' + $.getQueryParam('resourceId') + '&uploadUserId=' + uploadUserId + '&businessId=' + id + '&packageKey=' + packageKey,
            cancel: function (index, layero) {
                var params = layero.find('iframe').contents().find(':input').serializeJson();
                if ($.isEmptyObject(params)) {
                    return true;
                }
                $.extend(params, {
                    id: id,
                });
                $.ajax({
                    method: 'POST',
                    dataType: 'json',
                    url: url,
                    data: params,
                    success: function (result) {
                        if (result.success) {
                            parent.layer.msg(result.message, {time: 1000, icon: 1}, function () {
                                parent.layer.close(layerIndex);
                            });
                        } else {
                            parent.layer.msg(result.message, {time: 1000, icon: 2});
                        }
                    }
                });
                return false;
            }
        });
    });
};


